<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.2" />






<meta name="description" content="1. 原型简介1.1. 什么是原型原型是 Javascript 中的继承的基础，JavaScript 的继承就是基于原型的继承。 1.2. prototype 和 __proto__ 的区别 prototypeprototype 是函数才有的属性 __proto____proto__ 是每个对象都有的属性但 __proto__ 不是一个规范属性，只有部分浏览器实现了此属性，对应的标准属性是 [[P">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript 之原型到原型链™">
<meta property="og:url" content="http://xiezixi.oschina.io/2018/06/06/JS-原型链/index.html">
<meta property="og:site_name" content="个人博客">
<meta property="og:description" content="1. 原型简介1.1. 什么是原型原型是 Javascript 中的继承的基础，JavaScript 的继承就是基于原型的继承。 1.2. prototype 和 __proto__ 的区别 prototypeprototype 是函数才有的属性 __proto____proto__ 是每个对象都有的属性但 __proto__ 不是一个规范属性，只有部分浏览器实现了此属性，对应的标准属性是 [[P">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://xiezixi.oschina.io/blog/images/prototype1.png">
<meta property="og:image" content="http://xiezixi.oschina.io/blog/images/prototype2.png">
<meta property="og:image" content="http://xiezixi.oschina.io/blog/images/prototype3.png">
<meta property="og:image" content="http://xiezixi.oschina.io/blog/images/prototype4.png">
<meta property="og:image" content="http://xiezixi.oschina.io/blog/images/prototype5.png">
<meta property="og:updated_time" content="2018-06-06T07:34:03.887Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JavaScript 之原型到原型链™">
<meta name="twitter:description" content="1. 原型简介1.1. 什么是原型原型是 Javascript 中的继承的基础，JavaScript 的继承就是基于原型的继承。 1.2. prototype 和 __proto__ 的区别 prototypeprototype 是函数才有的属性 __proto____proto__ 是每个对象都有的属性但 __proto__ 不是一个规范属性，只有部分浏览器实现了此属性，对应的标准属性是 [[P">
<meta name="twitter:image" content="http://xiezixi.oschina.io/blog/images/prototype1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://xiezixi.oschina.io/2018/06/06/JS-原型链/"/>





  <title>JavaScript 之原型到原型链™ | 个人博客</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">个人博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">曦瓜皮</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>


 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://xiezixi.oschina.io/blog/2018/06/06/JS-原型链/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="曦瓜皮">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="个人博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">JavaScript 之原型到原型链™</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-06T15:34:03+08:00">
                2018-06-06
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/JavaScript/" itemprop="url" rel="index">
                    <span itemprop="name">JavaScript</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="1-原型简介"><a href="#1-原型简介" class="headerlink" title="1. 原型简介"></a>1. 原型简介</h2><h3 id="1-1-什么是原型"><a href="#1-1-什么是原型" class="headerlink" title="1.1. 什么是原型"></a>1.1. 什么是原型</h3><p>原型是 Javascript 中的继承的基础，JavaScript 的继承就是基于原型的继承。</p>
<h3 id="1-2-prototype-和-proto-的区别"><a href="#1-2-prototype-和-proto-的区别" class="headerlink" title="1.2. prototype 和 __proto__ 的区别"></a>1.2. prototype 和 __proto__ 的区别</h3><ul>
<li>prototype<br>prototype 是函数才有的属性</li>
<li>__proto__<br>__proto__ 是每个对象都有的属性<br>但 __proto__ 不是一个规范属性，只有部分浏览器实现了此属性，对应的标准属性是 [[Prototype]]</li>
</ul>
<h2 id="2-实例介绍"><a href="#2-实例介绍" class="headerlink" title="2. 实例介绍"></a>2. 实例介绍</h2><h3 id="2-1-构造函数创建对象"><a href="#2-1-构造函数创建对象" class="headerlink" title="2.1. 构造函数创建对象"></a>2.1. 构造函数创建对象</h3><p>使用构造函数创建一个对象：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> person = <span class="keyword">new</span> Person();</span><br><span class="line">person.name = <span class="string">'xiguapi'</span>;</span><br><span class="line"><span class="built_in">console</span>.log(person.name); <span class="comment">// xiguapi</span></span><br></pre></td></tr></table></figure></p>
<p>在这个例子中，Person 就是一个构造函数，我们使用 new 创建了一个实例对象 person。</p>
<h3 id="2-2-prototype"><a href="#2-2-prototype" class="headerlink" title="2.2. prototype"></a>2.2. prototype</h3><p>每个函数都有一个 prototype 属性，比如：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">&#125;</span><br><span class="line">Person.prototype.name = <span class="string">"xiguapi"</span>;</span><br><span class="line"><span class="keyword">var</span> person1 = <span class="keyword">new</span> Person();</span><br><span class="line"><span class="keyword">var</span> person2 = <span class="keyword">new</span> Person();</span><br><span class="line"><span class="built_in">console</span>.log(person1.name); <span class="comment">// xiguapi</span></span><br><span class="line"><span class="built_in">console</span>.log(person2.name); <span class="comment">// xiguapi</span></span><br></pre></td></tr></table></figure></p>
<p>其实，函数的 prototype 属性指向了一个对象，这个对象正是调用该构造函数而创建的实例的原型，也就是这个例子中的 person1 和 person2 的原型。<br>那什么是原型呢？你可以这样理解：每一个 JavaScript 对象( null，undefined 除外)在创建的时候就会与之关联另一个对象，这个对象就是我们所说的原型，每一个对象都会从原型”继承”属性。<br>用一张图表示构造函数和实例原型之间的关系：<br><img src="http://xiezixi.oschina.io/blog/images/prototype1.png" alt="prototype"><br>在这张图中我们用 Person.prototype 表示实例原型。<br>那么我们该怎么表示实例与实例原型，也就是 person 和 Person.prototype 之间的关系呢，这时候我们就要讲到第二个属性：</p>
<h3 id="2-3-proto"><a href="#2-3-proto" class="headerlink" title="2.3. __proto__"></a>2.3. __proto__</h3><p>每一个JavaScript对象(除了 null，undefined 外 )都具有的一个属性，叫 __proto__ ，这个属性会指向该对象的原型。<br>为了证明这一点,我们可以在火狐或者谷歌中输入：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> person = <span class="keyword">new</span> Person();</span><br><span class="line"><span class="built_in">console</span>.log(person.__proto__ === Person.prototype); <span class="comment">// true</span></span><br></pre></td></tr></table></figure></p>
<p>于是我们更新下关系图：<br><img src="http://xiezixi.oschina.io/blog/images/prototype2.png" alt="prototype"></p>
<h3 id="2-4-constructor"><a href="#2-4-constructor" class="headerlink" title="2.4. constructor"></a>2.4. constructor</h3><p>因为一个构造函数可以生成多个实例，这就要讲到第三个属性：constructor，每个原型都有一个 constructor 属性指向关联的构造函数。<br>为了验证这一点，我们可以尝试：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(Person === Person.prototype.constructor); <span class="comment">// true</span></span><br></pre></td></tr></table></figure></p>
<p>所以再更新下关系图：<br><img src="http://xiezixi.oschina.io/blog/images/prototype3.png" alt="prototype"><br>综上我们已经得出：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> person = <span class="keyword">new</span> Person();</span><br><span class="line"><span class="built_in">console</span>.log(person.__proto__ === Person.prototype); <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(Person.prototype.constructor === Person); <span class="comment">// true</span></span><br><span class="line"><span class="comment">// ES5 获取对象原型</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Object</span>.getPrototypeOf(person) === Person.prototype); <span class="comment">// true</span></span><br></pre></td></tr></table></figure></p>
<h3 id="2-5-实例与原型"><a href="#2-5-实例与原型" class="headerlink" title="2.5. 实例与原型"></a>2.5. 实例与原型</h3><p>当读取实例的属性时，如果找不到，就会查找与对象关联的原型中的属性，如果还查不到，就去找原型的原型，一直找到最顶层为止。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">Person.prototype.name = <span class="string">'Kevin'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> person = <span class="keyword">new</span> Person();</span><br><span class="line"></span><br><span class="line">person.name = <span class="string">'Daisy'</span>;</span><br><span class="line"><span class="built_in">console</span>.log(person.name) <span class="comment">// Daisy</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">delete</span> person.name;</span><br><span class="line"><span class="built_in">console</span>.log(person.name) <span class="comment">// Kevin</span></span><br></pre></td></tr></table></figure></p>
<p>在这个例子中，我们给实例对象 person 添加了 name 属性，当我们打印 person.name 的时候，结果自然为 Daisy。<br>但是当我们删除了 person 的 name 属性时，读取 person.name，从 person 对象中找不到 name 属性就会从 person 的原型也就是 person.<strong>proto</strong> ，也就是 Person.prototype中查找，幸运的是我们找到了 name 属性，结果为 Kevin。</p>
<h3 id="2-6-原型的原型"><a href="#2-6-原型的原型" class="headerlink" title="2.6. 原型的原型"></a>2.6. 原型的原型</h3><p>我们在 JavaScript 遇到的每个对象，实际上都是从 Object.prototype 对象克隆而来的，Object.prototype 对象就是它们的原型。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(Person.prototype.__proto__ === <span class="built_in">Object</span>.prototype); <span class="comment">// true</span></span><br></pre></td></tr></table></figure></p>
<p>其实原型对象就是通过 Object 构造函数生成的，结合之前所讲，实例的 __proto__ 指向构造函数的 prototype ，所以我们再更新下关系图：<br><img src="http://xiezixi.oschina.io/blog/images/prototype4.png" alt="prototype"></p>
<h3 id="2-7-原型链"><a href="#2-7-原型链" class="headerlink" title="2.7. 原型链"></a>2.7. 原型链</h3><p>Object.prototype 的原型是 null。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Object</span>.prototype.__proto__ === <span class="literal">null</span>) <span class="comment">// true</span></span><br></pre></td></tr></table></figure></p>
<p>所以 Object.prototype.__proto__  的值为 null 跟 Object.prototype 没有原型，其实表达了一个意思。<br>所以查找属性的时候查到 Object.prototype 就可以停止查找了。<br>最后一张关系图也可以更新为：<br><img src="http://xiezixi.oschina.io/blog/images/prototype5.png" alt="prototype"></p>
<h2 id="3-注意点"><a href="#3-注意点" class="headerlink" title="3. 注意点"></a>3. 注意点</h2><h3 id="3-1-constructor"><a href="#3-1-constructor" class="headerlink" title="3.1. constructor"></a>3.1. constructor</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> person = <span class="keyword">new</span> Person();</span><br><span class="line"><span class="built_in">console</span>.log(person.constructor === Person); <span class="comment">// true</span></span><br></pre></td></tr></table></figure>
<p>当获取 person.constructor 时，其实 person 中并没有 constructor 属性,当不能读取到 constructor 属性时，会从 person 的原型也就是 Person.prototype 中读取，正好原型中有该属性，所以：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">person.constructor === Person.prototype.constructor</span><br></pre></td></tr></table></figure></p>
<h3 id="3-2-proto"><a href="#3-2-proto" class="headerlink" title="3.2. __proto__"></a>3.2. __proto__</h3><p>其次是 __proto__ ，绝大部分浏览器都支持这个非标准的方法访问原型，然而它并不存在于 Person.prototype 中，实际上，它是来自于 Object.prototype ，与其说是一个属性，不如说是一个 getter/setter，当使用 obj.__proto__ 时，可以理解成返回了 <code>Object.getPrototypeOf(obj)</code>。</p>
<h3 id="3-3-继承"><a href="#3-3-继承" class="headerlink" title="3.3. 继承"></a>3.3. 继承</h3><p>继承意味着复制操作，然而 JavaScript 默认并不会复制对象的属性，相反，JavaScript 只是在两个对象之间创建一个关联，这样，一个对象就可以通过委托访问另一个对象的属性和函数，所以与其叫继承，委托的说法反而更准确些。<br>所有对象最终的基类都是 Object，因此 Object.prototype 是所有对象最上层的原型对象。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/06/04/ES6-箭头函数/" rel="next" title="ECMAScript6 之箭头函数™">
                <i class="fa fa-chevron-left"></i> ECMAScript6 之箭头函数™
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/06/07/JS-常用设计模式/" rel="prev" title="JavaScript 之常用设计模式">
                JavaScript 之常用设计模式 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/avatar.jpg"
               alt="曦瓜皮" />
          <p class="site-author-name" itemprop="name">曦瓜皮</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives/">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories/index.html">
                <span class="site-state-item-count">6</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        

      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-原型简介"><span class="nav-number">1.</span> <span class="nav-text">1. 原型简介</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-什么是原型"><span class="nav-number">1.1.</span> <span class="nav-text">1.1. 什么是原型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-prototype-和-proto-的区别"><span class="nav-number">1.2.</span> <span class="nav-text">1.2. prototype 和 __proto__ 的区别</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-实例介绍"><span class="nav-number">2.</span> <span class="nav-text">2. 实例介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-构造函数创建对象"><span class="nav-number">2.1.</span> <span class="nav-text">2.1. 构造函数创建对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-prototype"><span class="nav-number">2.2.</span> <span class="nav-text">2.2. prototype</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-proto"><span class="nav-number">2.3.</span> <span class="nav-text">2.3. __proto__</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-constructor"><span class="nav-number">2.4.</span> <span class="nav-text">2.4. constructor</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5-实例与原型"><span class="nav-number">2.5.</span> <span class="nav-text">2.5. 实例与原型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-6-原型的原型"><span class="nav-number">2.6.</span> <span class="nav-text">2.6. 原型的原型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-7-原型链"><span class="nav-number">2.7.</span> <span class="nav-text">2.7. 原型链</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-注意点"><span class="nav-number">3.</span> <span class="nav-text">3. 注意点</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-constructor"><span class="nav-number">3.1.</span> <span class="nav-text">3.1. constructor</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-proto"><span class="nav-number">3.2.</span> <span class="nav-text">3.2. __proto__</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-继承"><span class="nav-number">3.3.</span> <span class="nav-text">3.3. 继承</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">曦瓜皮</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.2"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  






  





  

  

  

  

  

  

</body>
</html>
